<template>
  <div class="article-detail-page">
    <nav class="nav"><span class="back" @click="back">&lt;</span> 面经详情</nav>
    <header class="header">
      <h1>{{ detail.stem }}</h1>
      <p>
        {{ detail.createdAt }} | {{ detail.views }} 浏览量 |
        {{ detail.likeCount }} 点赞数
      </p>
      <p>
        <img :src="detail.creatorAvatar" alt="" />
        <span>{{ detail.creatorName }}</span>
      </p>
    </header>
    <main class="body">
      {{ detail.content }}
    </main>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "ArticleDetailPage",
  async created() {
    // console.log(this.$route);
    /**
     * 动态路由传参 接受参数的方式是用params
     * /xxx 接受参数 $route.params
     *
     * 非动态路由传参 接受参数的方式是用query
     * ?xx=yy 接受参数 $route.query
     */
    // const id = this.$route.params.id;
    // console.log(this.$route.query.id);
    const id = this.$route.query.id;
    console.log(id);
    /**
     * 渲染详情页
     * 0. axios安装 引入
     * 1. 发请求 拿到数据
     *      请求地址: https://mock.boxuegu.com/mock/3083/articles/:id
            请求方式: get
     * 2. 在data中提供数据（把后端数据赋值 - 为了渲染页面）
     * 3. 渲染页面
     */
    const {
      data: { result },
    } = await axios.get(`https://mock.boxuegu.com/mock/3083/articles/${id}`);
    // console.log(result);
    this.detail = result;
  },
  data() {
    return {
      detail: {},
    };
  },
  methods: {
    back() {
      // console.log(this.$router);
      // 回退 - go(-1) 或者 back()
      this.$router.go(-1);
    },
  },
};
</script>

<style lang="less" scoped>
.article-detail-page {
  .nav {
    height: 44px;
    border-bottom: 1px solid #e4e4e4;
    line-height: 44px;
    text-align: center;
    .back {
      font-size: 18px;
      color: #666;
      position: absolute;
      left: 10px;
      top: 0;
      transform: scale(1, 1.5);
    }
  }
  .header {
    padding: 0 15px;
    p {
      color: #999;
      font-size: 12px;
      display: flex;
      align-items: center;
    }
    img {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      overflow: hidden;
    }
  }
  .body {
    padding: 0 15px;
  }
}
</style>